<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%> <%@ page import="com.lp.cfg.ProConfig"%> <%@ taglib
prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fn"
uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
  <head>
    <title><%=ProConfig.PROJECT_NAME %></title>
    <%@ include file="/WEB-INF/wechat/iot/common/resource_lib.jsp"%>
    <link
      type="text/css"
      href="<%=basePath%>/css/wechat/iot/login.css?<%=v%>"
      rel="stylesheet" />
  </head>
  <body>
    <div class="login">
      <div class="welcome">
        <span><%=ProConfig.SYS_APP_LOGIN_NAME %></span>
      </div>
      <div
        class="login-form jui-form_submit"
        data-options=" url:'/user/login',
												  submit:'.loginbtn',
												  success:'sunccessReturn' ">
        <div class="login-inp">
          <label>Account</label>
          <input
            validate="empty:Please enter your account"
            type-name="name"
            type="text"
            class="na" />
        </div>
        <div class="login-inp">
          <label>Password</label>
          <input
            validate="empty:Please enter your Password"
            type-name="password"
            type="password"
            class="pd" />
        </div>

        <div class="checkbox-remember">
          <input type="checkbox" id="saveLogin" />
          <label for="saveLogin" class="checkbox">Remember the password</label>
        </div>

        <div class="login-inp" id="login">
          <a href="javascript:;" class="loginbtn">login</a>
        </div>
      </div>
      <div class="login-txt">
        <a href="<%=basePath%>/service/wiot/login_sms">SMS login</a>
        &nbsp;&nbsp;|&nbsp;&nbsp;
        <a href="<%=basePath%>/service/wiot/register">Sign Up</a>
      </div>
    </div>
  </body>
  <script type="text/javascript">
    $(function () {
      iosInitForm('.login-inp input');
      var name = localStorage.getItem('na');
      var pd = localStorage.getItem('pd');
      if (pd != null && pd != '') {
        $('.pd').val(pd);
        $('#saveLogin').attr('checked', true);
      }
      if (name != null && name != '') {
        $('.na').val(name);
        if (localStorage.getItem('auto') == 1) {
          // 自动登录
          commonAjax(
            'POST',
            localUrl + '/user/login',
            { name: name, password: pd },
            function (data) {
              if (isOK(data)) {
                forward('/wiot/scene');
              }
            },
            function () {
              $.toptip(data.statusMsg, 'error');
            }
          );
        }
      }
    });
    function sunccessReturn(data) {
      if (isOK(data)) {
        localStorage.setItem('ucode', data.data.user_key);
        if ($('#saveLogin').is(':checked')) {
          localStorage.setItem('na', $('.na').val());
          localStorage.setItem('pd', $('.pd').val());
          localStorage.setItem('auto', '1');
        } else {
          localStorage.removeItem('na');
          localStorage.removeItem('pd');
        }
        forward('/wiot/scene');
      } else {
        $.toptip(data.statusMsg, 'error');
      }
    }
  </script>
</html>
